home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / access1g / listbox.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-08-25  |  3.5 KB  |  106 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Open & Save Data "
  5.    ClientHeight    =   2820
  6.    ClientLeft      =   6240
  7.    ClientTop       =   3840
  8.    ClientWidth     =   2655
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   2820
  13.    ScaleWidth      =   2655
  14.    ShowInTaskbar   =   0   'False
  15.    Begin VB.CommandButton Command4 
  16.       Caption         =   "EXIT"
  17.       Height          =   255
  18.       Left            =   1920
  19.       TabIndex        =   5
  20.       Top             =   2520
  21.       Width           =   675
  22.    End
  23.    Begin VB.CommandButton Command3 
  24.       Caption         =   "AddITem"
  25.       Height          =   2055
  26.       Left            =   2400
  27.       TabIndex        =   3
  28.       Top             =   360
  29.       Width           =   195
  30.    End
  31.    Begin VB.ListBox List1 
  32.       Height          =   2010
  33.       ItemData        =   "ListBox.frx":0000
  34.       Left            =   0
  35.       List            =   "ListBox.frx":0010
  36.       TabIndex        =   2
  37.       Top             =   360
  38.       Width           =   2295
  39.    End
  40.    Begin VB.CommandButton Command2 
  41.       Caption         =   "Load"
  42.       Height          =   255
  43.       Left            =   960
  44.       MousePointer    =   10  'Up Arrow
  45.       TabIndex        =   1
  46.       Top             =   2520
  47.       Width           =   855
  48.    End
  49.    Begin VB.CommandButton Command1 
  50.       Caption         =   "Save"
  51.       Height          =   255
  52.       Left            =   0
  53.       MousePointer    =   10  'Up Arrow
  54.       TabIndex        =   0
  55.       Top             =   2520
  56.       Width           =   855
  57.    End
  58.    Begin VB.Label Label1 
  59.       Height          =   255
  60.       Left            =   0
  61.       TabIndex        =   4
  62.       Top             =   0
  63.       Width           =   2655
  64.    End
  65. Attribute VB_Name = "Form1"
  66. Attribute VB_GlobalNameSpace = False
  67. Attribute VB_Creatable = False
  68. Attribute VB_PredeclaredId = True
  69. Attribute VB_Exposed = False
  70. Private Sub Command1_Click()
  71. On Error GoTo here 'if error skip it all and goto here:
  72. Dim lFile As Long, Item As Integer 'Dims
  73. lFile = FreeFile 'Open as
  74. Open App.Path & "\TestFile.txt" For Output As lFile 'open a file to save the items to
  75. For Item = 0 To List1.ListCount - 1 'find out how many items substract 1 (empty)
  76. Print #lFile, List1.List(Item) 'save the items
  77. Next Item 'finish For function
  78. Close #lFile 'close the file
  79. Exit Sub 'done
  80. here: MsgBox Error 'shows error if any
  81. End Sub
  82. Private Sub Command2_Click()
  83. On Error Resume Next
  84. Dim Item As Integer, ListItem As String 'Dims
  85. Open App.Path & "\TestFile.txt" For Input As #1 'opens the file to get items
  86. List1.Clear 'clear ListBox
  87. Do While Not EOF(1) 'Do until it reaches the end of the file
  88. Input #1, ListItem 'put the items in
  89. Item = Item + 1 'gets each item after item
  90. List1.AddItem ListItem 'add the items
  91. Loop 'do infinite times until it reaches the end of the file
  92. Close #1 'close the file
  93. Label1.Caption = "Entries: " & List1.ListCount 'display how many items are in the listbox
  94. End Sub
  95. Private Sub Command3_Click()
  96. List1.AddItem "Data to save" 'add a item
  97. Label1.Caption = "Entries: " & List1.ListCount 'added it again to refresh it
  98. End Sub
  99. Private Sub Command4_Click()
  100. Unload Me 'closes the program
  101. End Sub
  102. Private Sub Form_Load()
  103. Label1.Caption = "Entries: " & List1.ListCount 'displays amout of items in listbox when form loads
  104. MsgBox "Try using the Common Dialong control to let the user specify a file to open/save"
  105. End Sub
  106.